import dayjs from 'dayjs';
import { useTable, LIST_TYPE } from '@crud/index';
import { getList } from '@/api/crm-dyj/team';
import { toolGetDefaultDate } from '@/utils';
// import { toolOptions2Map } from '@/utils';

// 查询

// 表格
export const useTableList = (options: any = {}) => {
  const columns = [
    { label: '账号昵称', prop: 'nick_name', width: 200, render: 'nick_name', fixed: 'left' },
    { label: '手机号', prop: 'mobile', width: 130 },
    { label: '团队人数', prop: 'team_member_num', width: 120, sortable: 'custom' },
    { label: '抖音号监控数量', prop: 'monitor_num', width: 200, render: 'monitor_num', sortable: 'custom' },
    { label: 'DOU+账户金额', prop: 'hot_balance', width: 180, type: 'price', sortable: 'custom' },
    { label: '随心推账户金额', prop: 'ecp_balance', width: 180, type: 'price', sortable: 'custom' },
    { label: 'DOU+投放总订单数', prop: 'hot_order_num_total', width: 200, sortable: 'custom' },
    { label: 'DOU+投放总金额', prop: 'hot_budget_total', width: 180, type: 'price', sortable: 'custom' },
    { label: 'DOU+消耗总金额', prop: 'hot_cost_total', width: 180, type: 'price', sortable: 'custom' },
    { label: '随心推投放总订单数', prop: 'ecp_order_num_total', width: 180, sortable: 'custom' },
    { label: '随心推投放总金额', prop: 'ecp_budget_total', width: 180, type: 'price', sortable: 'custom' },
    { label: '随心推消耗总金额', prop: 'ecp_cost_total', width: 180, type: 'price', sortable: 'custom' },
    { label: '随心推成交订单数', prop: 'ecp_deal_order_total', width: 180, sortable: 'custom' },
    { label: '随心推成交总金额', prop: 'ecp_revenue_total', width: 180, type: 'price', sortable: 'custom' },
    { label: '随心推支付ROI', prop: 'pay_roi_total', width: 180 }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.DYJ,
    params: {
      leader_info: undefined,
      _dateRange: toolGetDefaultDate
    },
    columns: columns,
    getParams: ({ _dateRange = [], ...params }) => {

      if (_dateRange && _dateRange.length) {
        params.start_time = dayjs(_dateRange[0]).startOf('day').format('X');
        params.end_time = dayjs(_dateRange[1]).endOf('day').format('X');
      }
      params.sort_title = params.sort_field;
      params.sort_type = params.sort;

      return { ...params, sort_field: undefined, sort: undefined };
    },
    getList: getList
  });
};
